package com.example.user;

import com.example.shared.entity.User;
import com.example.shared.repository.UserRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@SpringBootApplication
@EnableDiscoveryClient
@EnableJpaRepositories(basePackages = "com.example.shared")
public class UserApplication {

	public static void main(String[] args) {
		SpringApplication.run(UserApplication.class, args);
	}

	@Bean
	public CommandLineRunner createUsers(UserRepository userRepository) {
		return (args) -> {
			User u = new User();
			u.setName("foo");
			BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
			u.setPassword(encoder.encode("bar"));
			userRepository.save(u);
		};
	}
}
